;;
;; Copyright (c) 2010, Justin Grant <justin at imagine27 dot com>
;; All rights reserved.

;; Redistribution and use in source and binary forms, with or without modification
;; are permitted provided that the following conditions are met:

;; Redistributions of source code must retain the above copyright notice, this list
;; of conditions and the following disclaimer.
;; Redistributions in binary form must reproduce the above copyright notice, this
;; list of conditions and the following disclaimer in the documentation and/or
;; other materials provided with the distribution.
;; Neither the name of the <ORGANIZATION> nor the names of its contributors may be
;; used to endorse or promote products derived from this software without specific
;; prior written permission.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE
;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;

(set! *warn-on-reflection* true)

(ns clijx.data
  (:import [java.awt Color]
           [javax.swing Timer]))


(def game (atom {:directions {:north [[1 3] [:west :east]]
                              :west  [[2 0] [:south :north]]
                              :south [[3 1] [:east :west]]
                              :east  [[0 2] [:north :south]]}}))

(def player1 (atom {}))

(defn reset-game-data [game]
  (swap! game assoc :display-width       320)
  (swap! game assoc :display-height      200)
  (swap! game assoc :game-top-border     30)
  (swap! game assoc :game-border         10)
  (swap! game assoc :diamond-color       (Color. 255 160 160))
  (swap! game assoc :diamond-p-color     (Color. 255 190 190))
  (swap! game assoc :edge-color          (Color. 200 200 200))
  (swap! game assoc :trail-points        [])
  (swap! game assoc :started             nil)
  (swap! game assoc :game-width (- (:display-width @game)
                                   (* 2 (:game-border @game))))
  (swap! game assoc :game-height (- (:display-height @game)
                                    (+ (:game-border @game)
                                       (:game-top-border @game))))
  (swap! game assoc :min-x (/ (- (:display-width @game)
                                 (:game-width @game)) 2))
  (swap! game assoc :max-x (- (:display-width @game)
                              (:min-x @game)))
  (swap! game assoc :min-y (- (:display-height @game)
                              (:game-height @game)
                              (:game-border @game)))
  (swap! game assoc :max-y (- (:display-height @game)
                              (:game-border @game)))
  (swap! game assoc :all-points [[(:min-x @game) (:min-y @game)]
                                 [(:min-x @game) (:max-y @game)]
                                 [(:max-x @game) (:max-y @game)]
                                 [(:max-x @game) (:min-y @game)]
                                 [(:min-x @game) (:min-y @game)]])

  (swap! player1 assoc :y (:max-y @game))
  (swap! player1 assoc :x (:min-x @game))
  (swap! player1 assoc :yp (:max-y @game))
  (swap! player1 assoc :xp (:min-x @game))
  (swap! player1 assoc :size 3)
  (swap! player1 assoc :dir nil)
  (swap! player1 assoc :prev-dir nil)
  (swap! player1 assoc :speed 1)
  (swap! player1 assoc :is-creating-trail nil)
  (swap! player1 assoc :paused nil))

;; #+debug-game
(def test-points
  ;;[[0 0] [100 0] [0 100] [100 100] [0 50] [75 0] [75 50] [85 50] [85 0] [85 100] [100 50]]]
  ;;[[0 0] [0 100] [100 100] [100 0] [0 0] [50 0] [50 25] [75 25] [75 0]]]
  [[0 0] [0 100] [100 100] [100 0] [0 0] [50 100] [50 75] [75 75] [75 100]])